package com.mxt.moviedemo.service.impl;


import com.mxt.moviedemo.dao.TicketMapper;
import com.mxt.moviedemo.entity.Movies;
import com.mxt.moviedemo.entity.PageResult;
import com.mxt.moviedemo.entity.Ticket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TicketServiceImpl {

    @Autowired
    private TicketMapper ticketMapper;

    @Override
    public PageResult<Ticket> getTicketByPage(PageRequest pageRequest) {
        List<Ticket> tickets = ticketMapper.getTicketByPage(pageRequest);
        // 过滤掉null元素
        List<Ticket> nonNullTicket = new ArrayList<>();
        for (Ticket ticket : tickets) {
            if (ticket != null) {
                nonNullTicket.add(ticket);
            }
        }
        int total = ticketMapper.getTotalTicket();
        return new PageResult<>(pageRequest.getPage(), pageRequest.getSize(), total, nonNullTicket);
    }


}
